<?php
/*
* Copyright (c) 2010 by Cediti
*
* You may distribute under the terms of either the GNU Lesser General
* Public License or the new BSD License, as specified in the README file.
*/

// created :    09/02/2010
// version :    02/04/2010

abstract class Cmis_Client_Rest_Generic_Abstract extends Cmis_Services_Protocol_Abstract
{
    protected function _callServices($url)
    {
        //TODO manage more errors and exception here
        /*/
        Debug::printTrace(2, 5);
        var_dump($url);
        /**/
        try
        {
        	if (Debug::is_active())
        	{
        		Debug::var_print($url, '<br /><br /><h1><a href="' . $url . '">test me</a></h1>');
        	}
            $this->getProtocolClient()->doGet($url);
        }
        catch (Cmis_Exception_Request_Request $e)
        {
            throw new Cmis_Exception_Services_Services($e->getMessage(), Cmis_Exception_Services_Services::FOLLOW_UP, $e);
        }

        if ($this->getProtocolClient()->getInfo('code') >= 300)
        {
            switch($this->getProtocolClient()->getInfo('code'))
            {
                default :
                    $msg = 'Error'; 
                    if ($this->getProtocolClient()->getInfo('type') == self::HTML)
                    {
                        $msg = $this->getProtocolClient()->toXml()->head->title;
                    }
                    throw new Cmis_Exception_Services_Services($msg, $this->getProtocolClient()->getInfo('code'));
                    break;
                case 404 :
                    throw new Cmis_Exception_Services_Services_NotFound('Not found', $this->getProtocolClient()->getInfo('code'));
                    break;
            }
        }

        return $this->getProtocolClient()->getResponse();
    }
}

# EOF
